package auctionatr

import grails.test.*

class UserTests extends GrailsUnitTestCase {
	
	def testuser
    protected void setUp() {
        super.setUp()
		
		mockForConstraintsTests(User)
			testuser = new User(username:'testuser',password:'pass',email:'test@test.de',birthday:(new Date() - 365*30),facebookName: 'admin', aboutUser: 'here i am', twitterName: 'admin', firstName: 'ad', lastName: 'min', street: 'here', zip: 8990, city: 'Stuttgart', accountNumber: 343443, bankCode: 'eee',role:'user',avatar: null, avatarType: null)
	}	

    protected void tearDown() {
        super.tearDown()
    }

    void testIdenticPassword() {
		
		def user = new User(password: "pass", password2:"pass")
		
		assertEquals(user.password,user.password2)
		
		user.password = "password"
		assertFalse "Validation should not succeed",
			user.validate()
    }
	
	
	void testBirthday(){
		
		def lastWeek = new Date() - 7
		testuser.birthday=lastWeek
		assertFalse "Validation should not succeed",
			testuser.validate()
		
		testuser.birthday=(new Date() - 365*30)
		
		assertTrue "Validation should succeed",
			testuser.validate()	
	}
	
	
	void testUserName() {
		
		testuser.username='=)=?'
		assertFalse "Validation should not succeed",
			testuser.validate()
			
		testuser.username='admin'
		
		assertTrue "Validation should succeed",
			testuser.validate()		
		
	}
	
	void testEmail() {
		
		testuser.email='1234'
		assertFalse "Validation should not succeed",
			testuser.validate()
			
		testuser.email='123.123'
		assertFalse "Validation should not succeed",
			testuser.validate()
			
		testuser.email='test@test.de'
		assertTrue "Validation should succeed",
			testuser.validate()
	}
	
}
